﻿using System;
using System.Security.Cryptography;
using System.Text;

static class UnitSecurity
{
    public static string MD5(string SourceText)
    {
        MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] bytValue, bytHash;
        bytValue = System.Text.Encoding.UTF8.GetBytes(SourceText);
        bytHash = md5.ComputeHash(bytValue);
        md5.Clear();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bytHash.Length; i++)
        {
            sb.Append(bytHash[i].ToString("x").PadLeft(2, '0'));
        }
        return sb.ToString();
    }
}